package csdn;

public class AddThread implements Runnable{
    private volatile static int sum = 0;
    public AddThread(){
        
    }
    
    public void run(){
        {
            for(int i = 0;i<100;++i){
                int temp = sum;
                temp = temp +1;
                try{
                    Thread.sleep(20);
                }catch(InterruptedException e){
                    System.out.println(e);
                }
                sum = temp;
                System.out.println(Thread.currentThread().getName() + " : This sum is "+ sum);
            }
        }
    }
    
    public static int getSum(){
        return sum;
    }
}
